{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "769fe55e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install memorizz and required dependencies\n",
    "%pip install -qU memorizz\n",
    "\n",
    "# Install Oracle database driver (required for Oracle provider)\n",
    "%pip install -qU oracledb\n",
    "\n",
    "# Install OpenAI SDK (for LLM and embeddings)\n",
    "%pip install -qU openai\n",
    "\n",
    "# Install requests (for tool examples like weather API)\n",
    "%pip install -qU requests\n",
    "\n",
    "# Install python-dotenv for .env file support (optional but recommended)\n",
    "%pip install -qU python-dotenv\n",
    "\n",
    "print(\"✅ All packages installed successfully!\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e76f476",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "852a4d3d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ[\"ORACLE_USER\"] = \"\"\n",
    "os.environ[\"ORACLE_PASSWORD\"] = \"VVxLC!\"\n",
    "os.environ[\"ORACLE_DSN\"] = \"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "712b99fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "# Get credentials from environment variables with defaults\n",
    "ORACLE_USER = os.getenv(\"ORACLE_USER\", \"test\")\n",
    "ORACLE_PASSWORD = os.getenv(\"ORACLE_PASSWORD\", \"test\")\n",
    "ORACLE_DSN = os.getenv(\"ORACLE_DSN\", \"test\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e50bab0",
   "metadata": {},
   "source": [
    "Place the need to run oracle in thick mode and the step that takes to make that happen and also place in the benfits.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f80ff495",
   "metadata": {},
   "outputs": [],
   "source": [
    "import oracledb\n",
    "\n",
    "print(\"Connecting to Oracle...\")\n",
    "print(f\"  User: {ORACLE_USER}\")\n",
    "print(f\"  DSN: {ORACLE_DSN}\")\n",
    "\n",
    "# Enabling python-oracledb Thick mode. \n",
    "# Might need to add instructions for the developers that point to INSTALL_ORACLE_CLIENT.md\n",
    "# Use the x86_64 version (matches your Python environment)\n",
    "oracledb.init_oracle_client(\n",
    "    lib_dir=os.path.expanduser(\"~/oracle/instantclient_19_16_x86_64\")\n",
    ")\n",
    "\n",
    "conn = oracledb.connect(user=ORACLE_USER, password=ORACLE_PASSWORD, dsn=ORACLE_DSN)\n",
    "cursor = conn.cursor()\n",
    "print(\"✓ Connected successfully!\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00e6459f",
   "metadata": {},
   "outputs": [],
   "source": [
    "  from memorizz.cli import setup_oracle\n",
    "  setup_oracle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69c8289a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import logging\n",
    "import os\n",
    "\n",
    "# Configure logging for Jupyter notebook\n",
    "os.environ['MEMORIZZ_LOG_LEVEL'] = 'INFO'\n",
    "\n",
    "# Set up proper logging configuration for notebooks\n",
    "logging.basicConfig(\n",
    "    level=logging.INFO,\n",
    "    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',\n",
    "    force=True  # This overwrites any existing configuration\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a6fcde59",
   "metadata": {},
   "outputs": [],
   "source": [
    "import getpass\n",
    "\n",
    "# Function to securely get and set environment variables\n",
    "def set_env_securely(var_name, prompt):\n",
    "    value = getpass.getpass(prompt)\n",
    "    os.environ[var_name] = value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "687650f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "set_env_securely(\"OPENAI_API_KEY\", \"Enter your OpenAI API key: \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de04aecd",
   "metadata": {},
   "outputs": [],
   "source": [
    "from memorizz.memory_provider.oracle import OracleProvider, OracleConfig\n",
    "\n",
    "# Create Oracle configuration\n",
    "oracle_config = OracleConfig(\n",
    "    user=ORACLE_USER, \n",
    "    password=ORACLE_PASSWORD,\n",
    "    dsn=ORACLE_DSN,\n",
    "    lazy_vector_indexes=False,\n",
    "    embedding_provider=\"openai\",\n",
    "    embedding_config={\n",
    "        \"model\": \"text-embedding-3-small\",\n",
    "        \"api_key\": os.getenv(\"OPENAI_API_KEY\"),\n",
    "    }\n",
    ")\n",
    "\n",
    "# Create Oracle Memory provider\n",
    "oracle_memory_provider = OracleProvider(oracle_config)\n",
    "print(\"✓ Oracle provider initialized!\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06b9137c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from memorizz.memagent.builders import MemAgentBuilder\n",
    "\n",
    "agent_builder_made = (MemAgentBuilder()\n",
    "    # 1. Core identity\n",
    "    .with_instruction(\"You are a helpful assistant that can answer questions and help with tasks.\")\n",
    "    # 2. Infrastructure\n",
    "    .with_memory_provider(oracle_memory_provider)\n",
    "    .with_llm_config({\n",
    "        \"provider\": \"openai\",\n",
    "        \"model\": \"gpt-4o-mini\",\n",
    "        \"api_key\": os.getenv(\"OPENAI_API_KEY\"),\n",
    "    })\n",
    "    .build()\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7aaa562d",
   "metadata": {},
   "outputs": [],
   "source": [
    "agent_builder_made.save()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10ca37e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "response = agent_builder_made.run(\"Hello! My name is Alice and I love hiking in the mountains.\")\n",
    "print(f\"Agent: {response}\\n\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef0c0d3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "response2 = agent_builder_made.run(\"What was my name again?\")\n",
    "print(f\"Agent: {response2}\\n\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00cad4a6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "memorizz_prod",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
